package com.nullpointer.xchat.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.nullpointer.xchat.R;
import com.nullpointer.xchat.object.User;
import com.nullpointer.xchat.object.UserInfo.GenderType;

public class ViewResultFragment extends Fragment {

	private TextView tvName;
	// private TextView tvBirthday;
	private ImageView ivGender;
	private TextView tvStatus;
	private GenderType gender;
	private final static String USER_KEY = "USER_KEY";
	private User user;
	private TextView tvId;

	public static ViewResultFragment newInstance(User user) {
		ViewResultFragment f = new ViewResultFragment();
		Bundle args = new Bundle();
		args.putString(USER_KEY, user.toJson());
		f.setArguments(args);
		return f;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		String value = getArguments().getString(USER_KEY);
		if (value == null) {
			//dismiss();
			return;
		}
		user = User.fromJsonToUser(value);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_view_result, container, false);
		findViewIds(view);
		init();
		setEvent();
		return view;
	}

	private void init() {
		//getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
		// tvBirthday.setText(DataManager.getInstance(getActivity())
		// .getUserBirthday());
		tvName.setText(user.getName());
		tvStatus.setText(user.getUserInfo().getStatus());
		tvId.setText("Profile id: " + user.getUserID());
		gender = user.getUserInfo().getGender();
		if (gender == GenderType.FEMALE) {
			ivGender.setImageResource(R.drawable.ic_female);
		} else if (gender == GenderType.MALE) {
			ivGender.setImageResource(R.drawable.ic_male);
		} else if (gender == GenderType.ANY) {
			ivGender.setImageResource(R.drawable.ic_other);
		}
	}

	private void setEvent() {

	}

	private void findViewIds(View view) {
		tvName = (TextView) view.findViewById(R.id.tv_name);
		// tvBirthday = (TextView) view.findViewById(R.id.tv_birthday);
		tvStatus = (TextView) view.findViewById(R.id.tv_status);
		tvId = (TextView) view.findViewById(R.id.tv_id);
		ivGender = (ImageView) view.findViewById(R.id.iv_gender);

	}
}
